package 代码随想录_补充题目;

/**
 * @author zx
 * @create 2023-02-08 22:09
 */
public class 比较含退格的字符串_844 {
    public boolean backspaceCompare(String s, String t) {
        return helper(s).equals(helper(t));
    }
    private String helper(String str){
        StringBuilder res = new StringBuilder();
        for(int i = 0;i < str.length();i++){
            if(str.charAt(i) == '#'){
                if(res.length() > 0){
                    res.deleteCharAt(res.length() - 1);
                }
            }else{
                res.append(str.charAt(i));
            }
        }
        return res.toString();
    }
}
